package main.java.trans;

import java.util.NoSuchElementException;

import main.java.Employee;
import main.java.PaymentClassification;
import main.java.PayrollDatabase;
import main.java.Transaction;
import main.java.classification.CommissionedClassification;
import main.java.exception.NotCommissionedClassificationException;

public class SalesReceiptTransaction implements Transaction {

    private int empId;
    private String date;
    private double amount;
    public SalesReceiptTransaction(int empId, String date, double amount) {
        this.empId = empId;
        this.date = date;
        this.amount = amount;
    }
@Override
public void execute() {

    Employee e = PayrollDatabase.getEmployee(empId);
    if (e == null)
    throw new NoSuchElementException();
    PaymentClassification pc = e.getPaymentClassification();
    if(pc instanceof CommissionedClassification){
        CommissionedClassification cc = (CommissionedClassification) pc;
    
        SalesReceipt sr = new SalesReceipt(date,amount);
        cc.addSalesReceipt(sr);
    }else {
        throw new NotCommissionedClassificationException();
    }


    
}
}
